package com.ctrip.demo.leetcode;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @author xs.wu
 */
public class LeetCode1791 {

    public static void main(String[] args) {

        System.out.println(findCenter1(new int[][]{{1, 2}, {2, 3}, {4, 2}}));

        System.out.println(UUID.randomUUID().toString());

        System.out.println(new Timestamp(System.currentTimeMillis()));

    }


    public static int findCenter1(int[][] edges) {

        int first = edges[0][0];
        int second = edges[0][1];

        if (first == edges[1][0] || first == edges[1][1]) {
            return first;
        }
        return second;



    }

    public static int findCenter(int[][] edges) {

        int m = edges.length, n = edges[0].length;
        Map<Integer, Integer> map = new HashMap();
        for(int i = 0; i < m; i ++) {
            int first = edges[i][0];
            int second = edges[i][1];
            map.put(first, map.getOrDefault(first, 0) + 1);
            map.put(second, map.getOrDefault(second, 0) + 1);
        }
        int res = 0;
        for (Map.Entry<Integer,Integer> entry : map.entrySet()) {
            if (entry.getValue() == m) {
                res = entry.getKey();
            }
        }

        return res;


    }
}
